package com.itheima.grow.util;

import com.itheima.grow.constant.EmailTemplateConstant;
import com.itheima.grow.model.enums.EmailTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.mail.MailProperties;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import java.util.Date;

/***
 * 发送邮件工具类
 */
@Component
@Slf4j
public class SentEmailUtil {

    @Resource
    private JavaMailSender javaMailSender;

    @Resource
    private MailProperties mailProperties;



    public void sentEmail1(Integer emailType,String username){
        String name="谢庭胜";
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(mailProperties.getUsername());
        message.setSentDate(new Date());
        if(EmailTypeEnum.ONE.getValue()==emailType){
            //新增SFT工单_区域财务经理通知邮件
            message.setSubject(EmailTemplateConstant.INFORM_TITLE1);
            message.setText(String.format(EmailTemplateConstant.PROCESSOR_INFORM_TEMPLATE1,name));
        }else if (EmailTypeEnum.TWO.getValue()==emailType){
            message.setSubject(EmailTemplateConstant.INFORM_TITLE2);
            message.setText(String.format(EmailTemplateConstant.PROCESSOR_INFORM_TEMPLATE2,name));
        }else {
            message.setSubject(EmailTemplateConstant.INFORM_TITLE3);
            message.setText(String.format(EmailTemplateConstant.PROCESSOR_INFORM_TEMPLATE3,name));
        }
        javaMailSender.send(message);
    }
}
